package com.sq.partner.manager.service.impl;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Service;

import com.sq.partner.manager.dao.IGatewayChannelInfoConfigDao;
import com.sq.partner.manager.dao.IGatewayPolicyDao;
import com.sq.partner.manager.mybatis.model.GatewayChannelInfo;
import com.sq.partner.manager.service.IGatewayCarPolicyListService;
import com.sq.partner.manager.service.IGatewayNocarPolicyListService;
import com.sq.partner.manager.util.Page;
import com.sq.partner.manager.util.excel.ExcelEntity;
import com.sq.partner.manager.util.excel.ExportExcelBuilderTool;

@Service
public class GatewayCarPolicyListServiceImpl implements
		IGatewayCarPolicyListService {

	@Resource
	ExportExcelBuilderTool exportExcelBuilderTool;

	@Resource
	private IGatewayPolicyDao policyDao;

	@Resource
	private IGatewayChannelInfoConfigDao channelInfoConfigDao;

	@Override
	public Page queryCarPolicyPageByCriteria(Page page) throws Exception {
		return policyDao.queryCarPolicyPageByCriteria(page);
	}

	@Override
	public List<Map<String, Object>> queryCarPolicyListByCriteria(
			Map<String, Object> map) throws Exception {
		return policyDao.queryCarPolicyListByCriteria(map);
	}

	@Override
	public void downloadCarPolicyFile(
			List<Map<String, Object>> carPolicyList,
			HttpServletResponse response) throws Exception {

		ExcelEntity excel = new ExcelEntity();
		excel.setResults(carPolicyList);
		excel.setFileName("CarPolicyInfo");
		excel.setTitles("保单号,投保单位,投保单位子机构,投保方案,含税保费,车船税,保单提交日期,起保日期,终保日期,保单状态");
		excel.setTitleKeys("POLNO,CHANNEL_NAME,SUB_CHANNEL_NAME,INSU_PLAN_NAME,PREMIUM,VHL_TAX,INSERT_TIME,BEGIN_DATE,END_DATE,STATE_ID");
		excel.setColumns("35,10,25,25,30,15,15,10,15,23");

		exportExcelBuilderTool.buildExcel(response,excel);	
	}

	@Override
	public List<Map> queryChannelListOfNocar(
			GatewayChannelInfo channelInfo,String flag) throws Exception {
		return channelInfoConfigDao.queryChannelInfoList(channelInfo,flag);
	}
}
